package com.muqi.app.user.widget;

import java.util.Calendar;

import com.muqi.app.qlearn.student.R;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RecordTimeEntry extends RelativeLayout implements TimePickerDialog.OnTimeSetListener {
	public static final String TIMEPICKER_TAG = "timepicker";
	private TextView mTitle;
	private TextView mDateText;
	private TimePickerDialog timePickerDialog;
	private FragmentActivity mActivity;

	public RecordTimeEntry(FragmentActivity mActivity, String title) {
		super(mActivity);
		this.mActivity = mActivity;
		init(mActivity);
		final Calendar calendar = Calendar.getInstance();
		timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY) ,
				calendar.get(Calendar.MINUTE), true, false);
		mTitle.setText(title);
	}

	public RecordTimeEntry(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public RecordTimeEntry(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.record_date_selecter_entry, this);
		mTitle = (TextView) view.findViewById(R.id.title);
		mDateText = (TextView) view.findViewById(R.id.recordDatetext);
		mDateText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mActivity != null) {
					 timePickerDialog.setVibrate(true);
		             timePickerDialog.setCloseOnSingleTapMinute(false);
		             timePickerDialog.show(mActivity.getSupportFragmentManager(), TIMEPICKER_TAG);
				}
			}
		});
	}

	public void setEditSize(float size) {
		mDateText.setTextSize(size);
	}

	public void setEditColor(int resId) {
		mDateText.setTextColor(resId);
	}
	/**
		 * 
		 */
	public String getDateTextValue() {
		return mDateText.getText().toString().trim();
	}

	@Override
	public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
		mDateText.setText(hourOfDay + ":" + minute);
	}
}
